<template>
  <div class="home_wrap" id="home_wrap">
    <!-- 标头 -->
    <div class="honme_top">
<!--      <div class="red_top_bg" id="red_top_bg">-->
<!--        <div class="logo">-->
<!--          <img :src="logo">-->
<!--        </div>-->
<!--        <div class="language" @click="$router.push('/language')">-->
<!--          <img :src="language_logo">-->
<!--        </div>-->
<!--      </div>-->
      <!-- 轮播图 -->
      <div class="pageLogo" style="padding: 16px 16px 0" v-if="logo">
        <img :src="logo" style="height: 44px;width: auto">
      </div>
      <div class="swiper_container block_div">
        <van-swipe v-show="loading" :autoplay="2500" class="swiper-container">
          <van-swipe-item v-for="(image, index) in banners" :key="index" @click="jump(image.url)">
            <img :src="image.img">
          </van-swipe-item>
        </van-swipe>
      </div>
      <div class="block_div newTab">
        <div class="tabItem"  @click="$router.push('/book')">
          <img src="@/assets/img/company.png" class="tabImg">
          <div class="tabTex">公司</div>
        </div>
        <div class="tabItem" @click="$router.push('/draw')">
          <img src="@/assets/img/prize.png" class="tabImg">
          <div class="tabTex">抽奖</div>
        </div>
<!--        <div class="tabItem">-->
<!--          <img src="@/assets/img/sign.png" class="tabImg">-->
<!--          <div class="tabTex">签到</div>-->
<!--        </div>-->
<!--        /notice-->
        <div class="tabItem" @click="$router.push('/notice')">
          <img src="@/assets/img/notice.png" class="tabImg">
          <div class="tabTex">公告</div>
        </div>
      </div>
    </div>
    <!-- 滚动消息 -->
    		<div class="block_div notice" @click="$router.push('/notice')">
    			<van-notice-bar  left-icon="volume-o" :text="notice.title" background="linear-gradient(90deg, #BFE0FF 0%, #F1FAFE 100%)"
                           color="#000"
          />
    		</div>
<!--    		<div class="block_div  work_box">-->
<!--    			<div class="flex_center">-->
<!--    				<div v-for="(item,index) in menus" class="item" @click='jump(item.url)'>-->
<!--    					<div class="item_img"><img :src="require('../img/'+item.logo)" alt=""></div>-->
<!--    					<p class="item_title">{{item.title}}</p>-->
<!--    				</div>-->
<!--    			</div>-->
<!--    			<div class="flex_center">-->
<!--    				<div v-for="(item,index) in menus2" class="item" @click='jump(item.url)'>-->
<!--    					<div class="item_img"><img :src="require('../img/'+item.logo)" alt=""></div>-->
<!--    					<p class="item_title">{{item.title}}</p>-->
<!--    				</div>-->
<!--    			</div>-->
<!--    		</div>-->
    <!-- 货币价格 -->
<!--    <div class="currency_tips">-->
<!--      {{ $t('index.exchangeRate') }}-->
<!--    </div>-->

<!--    <div class="block_div currency_wrap">-->
<!--      <van-swipe style="height: 70px;" :autoplay="2000" vertical :show-indicators="false">-->
<!--        <van-swipe-item v-for="(lang,index) in langs" :key="index" @click="$router.push('/currency')">-->
<!--          <div class="currency_detail">-->
<!--            <div class="flex_center currency">-->
<!--              <div class="flex_center logo">-->
<!--                <img :src="lang.logo" alt="">-->
<!--                <p>{{ lang.symbol }}</p>-->
<!--              </div>-->
<!--              <div class="price">-->
<!--                <div>-->
<!--                  <span>1 USD</span>-->
<!--                  <span> ≈ {{ lang.price }} {{ lang.symbol }}</span>-->
<!--                </div>-->
<!--              </div>-->
<!--            </div>-->
<!--          </div>-->
<!--        </van-swipe-item>-->
<!--      </van-swipe>-->
<!--    </div>-->

    <!-- 项目列表 -->
<!--    <div class="currency_tips">-->
<!--      <div class="cuL">理财产品</div>-->
<!--      <div class="cuR">限购一份</div>-->
<!--    </div>-->
<!--    <div class="currency_tips">-->
<!--      {{ $t('index.recommendedItem') }}-->
<!--    </div>-->

<div class="block_div">
  <leveList :list="items"></leveList>
</div>
<!--    <div class="items">-->
<!--      <div v-for="(item,index) in items" class="block_div item"-->
<!--           @click="$router.push('/invest/detail/'+item.id)">-->
<!--        <div class="logo">-->
<!--          <img v-lazy="item.img2"/>-->
<!--          <div>{{ item.title }}</div>-->
<!--        </div>-->
<!--        <div class="flex_center detail">-->
<!--          <div>-->
<!--            <div><span class="detail_name">{{ $t('index.amount') }}</span><span-->
<!--                class="detail_num">{{ common.currency_symbol_basic() }}{{ common.precision_basic(item.min) }}</span>-->
<!--            </div>-->
<!--            <div><span class="detail_name">{{ $t('index.cycle') }}</span><span-->
<!--                class="detail_num">{{ item.day }}{{ item.type == 3 ? $t('index.hour') : $t('index.day') }}</span></div>-->
<!--          </div>-->
<!--          <div>-->
<!--            <div><span class="detail_name">{{ item.type == 1 ? $t('index.dailyRate') : $t('index.rate') }}</span><span-->
<!--                class="detail_num">{{ item.rate }}%</span></div>-->
<!--            <div><span class="detail_name">{{ $t('invest.income') }}</span><span-->
<!--                class="detail_num">{{ common.currency_symbol_basic() }}{{ change(item) }}</span></div>-->
<!--          </div>-->
<!--        </div>-->
<!--      </div>-->
<!--    </div>-->
    <!-- APP -->
<!--    <div v-if="!isApp&&app.show" id="download_app" class="flex_center">-->
<!--      <div class="flex_center">-->
<!--        <div class="app_close" @click="closeDown()">-->
<!--          X-->
<!--        </div>-->
<!--        <div class="app_logo">-->
<!--          <img :src="app.logo" alt="" srcset="">-->
<!--        </div>-->
<!--        <div class="app_name">-->
<!--          <p>{{ app.name }}</p>-->
<!--        </div>-->
<!--      </div>-->
<!--      <div class="basic_btn down_btn" @click="jump(app.url)">-->
<!--        {{ $t('index.downApp') }}-->
<!--      </div>-->
<!--    </div>-->
    <!-- 弹窗 -->
    <van-dialog v-model="show_tc" :confirmButtonText="$t('utils.confirm')">
      <div class="popup" v-html="tc_content"></div>
    </van-dialog>
    <!-- 客服图标 -->
    <div class="kefu" :class="show_kefu?'':'kefu_hide'" @click="kefu_to">
      <img class="kefu_img" src="@/assets/img/kefu.png">
    </div>
  </div>
</template>

<script>
import Vue from 'vue';
import Fetch from '../../utils/fetch';
import Api from "../../interface/index"
import axios from 'axios'
import leveList from "@/components/leveList.vue";
import {
  Swipe,
  SwipeItem,
  Progress,
  Dialog,
  Field,
  Popup,
  NoticeBar,
  Lazyload,
  Search
} from "vant";

Vue.use(Progress).use(Dialog).use(Field).use(Popup).use(NoticeBar).use(Lazyload).use(Search);

export default {
  name: "Index",
  components: {
    VanSwipe: Swipe,
    VanSwipeItem: SwipeItem,
    leveList
  },
  data() {
    return {
      language_logo: localStorage.getItem('language_logo'),
      logo: localStorage.getItem("logo2"),
      menus: [{
        "title": this.$t('user.recharge'),
        "logo": "index/receive.png",
        "url": "/recharge"
      },
        {
          "title": this.$t('user.withdraw'),
          "logo": "index/send.png",
          "url": "/withdraw"
        },
        {
          "title": this.$t('savings.savings'),
          "logo": "user/savings.png",
          "url": "/savings"
        }
      ],
      menus2: [
        {
          "title": this.$t('goods.goods'),
          "logo": "index/goods.png",
          "url": "/goods"
        },
        {
          "title": this.$t('user.luckyDraw'),
          "logo": "index/luckyDraw.png",
          "url": "/draw"
        },
        {
          "title": this.$t('user.faq'),
          "logo": "user/question.png",
          "url": "/questions"
        }
      ],
      show_kefu: false,
      loading: false,
      notice: [],
      show_tc: false,
      tc_content: "",
      banners: [],
      items: [],
      langs: [],
      isApp: true,
      app: {
        "show": false,
        "name": "",
        "url": "",
        "logo": "",
      },
      value: ''
    };
  },
  created() {
    if (window.plus) {
      plus.navigator.setStatusBarBackground('#FFFFFF');
      plus.navigator.setStatusBarStyle('dark');
    }
    this.$parent.footer('index');
  },
  mounted() {
    this.start();
    var that = this;
    document.body.addEventListener("scroll", function () {
      if (!that.show_kefu) {
        return;
      }
      that.show_kefu = false;
    }, false);
    document.addEventListener('click', function (ev) {
      if (ev.target.className != 'kefu_img') {
        that.show_kefu = false;
      }
    }, false);
  },
  methods: {
    change(item) {
      if (item.type == 1) {
        return this.common.precision_basic(item.min * item.rate * item.day / 100);
      } else {
        return this.common.precision_basic(item.min * item.rate / 100);
      }
    },
    kefu_to() {
      if (this.show_kefu) {
        const currentTime = new Date();
        const currentHour = currentTime.getHours();
        const currentMinute = currentTime.getMinutes();
        if (
            (currentHour === 9 && currentMinute >= 0) ||
            (currentHour > 9 && currentHour < 23) ||
            (currentHour === 23 && currentMinute === 0)
        ) {
          Fetch('/index/service_list').then(res => {
            if(res.data && res.data.list.length > 0){
              this.$router.push('/service/' + res.data.list[0].id);
            }
          })
        } else {
          this.$toast('客服服务时间早上9点--晚上11点');
        }
      }
      this.show_kefu = !this.show_kefu;
    },
    jump(url) {
      if (url.indexOf('http') == 0) {
        window.location.href = url;
      } else {
        this.$router.push(url);
      }
    },
    start() {
      Fetch('/index/int').then((r) => {
        block: {
          if (r.data.popup.show == 1) {
            var popup_show = sessionStorage.getItem("popup_show");
            sessionStorage.setItem("popup_show", r.data.popup.num);
            if (popup_show != null && popup_show == 1) {
              break block;
            }
            this.tc_content = r.data.popup.content;
            this.show_tc = true;
          }
        }
        this.banners = r.data.banner;
        this.notice = r.data.notice;
        this.langs = r.data.langs;
        this.items = r.data.items;
        this.loading = true;

        this.app = r.data.version;
        this.showApp();
      });
    },
    showApp() {
      if (window.plus) {
        this.isApp = true;
      } else {
        if (this.app.show) {
          this.isApp = false;
          // document.getElementById('red_top_bg').style.top = '60px';
          // document.getElementById('home_wrap').style.paddingTop = '60px';
        }
      }
    },
    closeDown(url) {
      this.app.show = false;
      document.getElementById('red_top_bg').style.top = '0';
      document.getElementById('home_wrap').style.paddingTop = '0';
    }
  }
};
</script>

<style lang="less" scoped>
.home_wrap {
  margin-bottom: 60px;
  min-height: 100vh;
  background: linear-gradient(180deg, #D8E9FE 35%, #F1FAFE 100%);
}
.honme_top{
  background-image: url(../../assets/img/indexBac.png);
  background-size: auto 100%;
}
.red_top_bg {
  position: fixed;
  top: 0;
  z-index: 10;
  height: 68px;
  padding: 10px 0;
  background: #FFFFFF;

  .logo {
    position: absolute;
    top: 10px;
    left: 3%;
    height: 48px;

    img {
      height: 100%;
    }
  }

  .language {
    position: absolute;
    top: 19px;
    right: 2%;
    height: 36px;

    img {
      height: 100%;
    }
  }
}

.swiper_container {
  // min-height: 182px;
  position: relative;
}

.swiper-container {
  width: 100%;
  padding: 10px 0 0 0;
  overflow: hidden;
  border-radius: 5px;

  .van-swipe-item {
    overflow: hidden;
  }

  img {
    height: 100%;
    width: 100%;
  }
}

.newTab {
  padding: 16px 0 20px;
  display: flex;
  justify-content: space-around;
  .tabItem {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    .tabImg {
      width: 44px;
      height: 44px;
    }

    .tabTex {
      margin-top: 5px;
      font-size: 12px;
    }
  }
}
.notice {
  margin-bottom: 10px;
}

.work_box {
  padding: 10px 0 0 0;
  height: 160px;
  margin-bottom: 15px;

  .item {
    width: 33.33%;
    text-align: center;
    margin-bottom: 10px;

    .item_img {
      width: 100%;
      border-radius: 5px;
      overflow: hidden;

      img {
        width: 44px;
        height: 44px;
        padding: 4px;
      }
    }

    .item_title {
      width: 100%;
      line-height: 14px;
      font-size: 12px;
      color: #333333;
      text-align: center;
      transform: scale(0.85);
    }
  }
}

.currency_wrap {
  margin-bottom: 15px;

  img {
    width: 40px;
  }

  .currency_detail {
    padding: 20px 0;
  }

  .currency {
    justify-content: space-around;

    p {
      font-size: 14px;
      font-weight: bold;
    }

    .logo {
      p {
        margin-left: 5px;
      }
    }

    .price {
      color: #3CB371;
      font-weight: bold;
    }
  }
}

.popup {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  flex: 1;
  max-height: 60vh;
  padding: 26px 24px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 20px;
}

.currency_tips {
  margin-bottom: 16px;
  margin-left: 3%;
  display: flex;
  align-items: center;
  .cuL{
    font-size: 16px;
    font-weight: bold;
    margin-right: 10px;
  }
  .cuR{
    background: linear-gradient(90deg, #FFFFFF 0%, #000000 0%, #1878F9 0%, #399BFC 100%);
    padding: 4px 10px;
    border-radius: 10px;
    color: #ffffff;
  }
}

.items {
  margin-bottom: 20px;

  .item {
    margin-bottom: 10px;


    .logo {
      position: relative;

      div {
        position: absolute;
        bottom: 0px;
        width: 100%;
        background: #FFFFFF;
        height: 30px;
        line-height: 30px;
        opacity: 0.8;
        font-weight: bold;
        padding: 0 10px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      img {
        width: 100%;
        border-radius: 5px;
        max-height: 260px;
      }
    }

    .detail {
      padding: 15px;
      line-height: 2;

      .detail_name {
      }

      .detail_num {
        font-weight: bold;
        color: #3CB371;
      }
    }
  }
}

#download_app {
  position: fixed;
  background: #fff;
  width: 100%;
  top: 0;
  height: 60px;
  z-index: 11;
  justify-content: space-between;
  box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.2);
  padding: 0 20px 0 0;

  .app_close {
    color: #999;
    width: 50px;
    line-height: 60px;
    height: 60px;
    text-align: center;
  }

  .app_logo {
    margin-right: 5px;

    img {
      height: 30px;
    }
  }

  .down_btn {
    padding: 0 15px;
    width: unset;
    height: 32px;
    line-height: 32px;
  }
}

/deep/ .van-notice-bar {
  border-radius: 5px;
}
</style>
